package com.hanko.designpattern.singleton;

/**
 * 内部静态类方式
 *优点：静态内部类不会在InnerStaticSingleton类加载时加载，
 * 而在调用getInstance()方法时才加载
 *缺点：存在反射攻击或者反序列化攻击
 * @author hanko
 * @version 1.0
 * @date 2020/9/15 10:03
 */
public class InnerStaticSingleton {
    //特点一：构造函数私有
    private InnerStaticSingleton(){

    }
    //特点二：静态内部类
    private static class InnerSingleton{
        private static InnerSingleton instance = new InnerSingleton();
    }

    public InnerSingleton getInstance(){
        return InnerSingleton.instance;
    }

    public void doSomething(){
        //do Something
    }
}
